/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sisgraf.backup;

import java.io.File;
import java.util.Calendar;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;


/**
 *
 * @author Administrador
 */
public class BackupDeDados {
public void criaArquivoBackup()
{
     Calendar data = Calendar.getInstance();
     javax.swing.JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
     UIManager.put("FileChooser.openDialogTitleText", "Selecione o diretório para salvar o Backup");
     UIManager.put("FileChooser.openButtonText", "Salvar");
     UIManager.put("FileChooser.lookInLabelText", "Salvar em:");
     UIManager.put("FileChooser.filesOfTypeLabelText", "Salvar como tipo:");
     UIManager.put("FileChooser.fileNameLabelText", "Nome do arquivo:");
     SwingUtilities.updateComponentTreeUI(jFileChooser1);
     jFileChooser1.setSelectedFile(new File("backup-"+data.get(Calendar.DAY_OF_MONTH)+"-"+((data.get(Calendar.MONTH))+(1))+"-"+ data.get(Calendar.YEAR)));
     jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
     jFileChooser1.setAcceptAllFileFilterUsed(false);
     jFileChooser1.setApproveButtonToolTipText("Salvar Backup no" +
    		" diretório selecionado");
   FileNameExtensionFilter filter = new FileNameExtensionFilter("SQL", "sql");

     jFileChooser1.setFileFilter(filter);

 int retorno = jFileChooser1.showOpenDialog(null);

  if(retorno == JFileChooser.APPROVE_OPTION)
    {

     try
	{
 		String comando="C:\\Arquivos de programas\\MySQL\\MySQL Server 6.0\\bin\\mysqldump.exe";
  		ProcessBuilder pb=new ProcessBuilder(comando,"--user=root","--password=","sisgraf","--result-file="+jFileChooser1.getSelectedFile()+".sql");
  		pb.start();
  		JOptionPane.showMessageDialog(null,"Backup realizado com sucesso!!!");
        }
	catch(Exception exc)
	{
	exc.printStackTrace();
	}


	jFileChooser1.disable();
	}
	 if(retorno == JFileChooser.CANCEL_OPTION)
	  	  jFileChooser1.disable();
	}

}